Next: Drafts, Previous: Archived Messages, Up: Composing Messages [Contents][Index]
All them variables, they make my head swim.
So what if you want a different Organization and
signature based on what groups you post to? And you post both
from your home machine and your work machine, and you want
different From lines, and so on?
One way to do stuff like that is to write clever hooks that
change the variables you need to have changed. That’s a bit
boring, so somebody came up with the bright idea of letting the
user specify these things in a handy alist. Here’s an
example of a gnus-posting-styles variable:
((".*"
(signature "Peace and happiness")
(organization "What me?"))
("^comp"
(signature "Death to everybody"))
("comp.emacs.i-love-it"
(organization "Emacs is it")))
As you might surmise from this example, this alist consists of
several styles. Each style will be applicable if the
first element “matches”, in some form or other. The
entire alist will be iterated over, from the beginning towards
the end, and each match will be applied, which means that
attributes in later styles that match override the same
attributes in earlier matching styles. So
‘comp.programming.literate’ will have
the ‘Death to everybody’ signature and
the ‘What me?’ Organization
header.
The first element in each style is called the
match. If it’s a string, then Gnus will try to
regexp match it against the group name. If it is the form
(header match regexp), then
Gnus will look in the original article for a header whose name is
match and compare that regexp.
match and regexp are strings. (The original
article is the one you are replying or following up to. If you
are not composing a reply or a followup, then there is nothing to
match against.) If the match is a function symbol,
that function will be called with no arguments. If it’s a
variable symbol, then the variable will be referenced. If
it’s a list, then that list will be evaled. In
any case, if this returns a non-nil value, then the
style is said to match.
Each style may contain an arbitrary amount of
attributes. Each attribute consists of a
(name value) pair. In
addition, you can also use the (name :file
value) form or the (name
:value value) form. Where :file
signifies value represents a file name and its
contents should be used as the attribute value,
:value signifies value does not represent
a file name explicitly. The attribute name can be one of:
signaturesignature-filex-face-fileaddress, overriding
user-mail-addressname, overriding
(user-full-name)bodyNote that the signature-file attribute honors the
variable message-signature-directory.
The attribute name can also be a string or a symbol. In that
case, this will be used as a header name, and the value will be
inserted in the headers of the article; if the value is
nil, the header name will be removed. If the
attribute name is eval, the form is evaluated, and
the result is thrown away.
The attribute value can be a string, a function with zero
arguments (the return value will be used), a variable (its value
will be used) or a list (it will be evaled and the
return value will be used). The functions and sexps are
called/evaled in the message buffer that is being
set up. The headers of the current article are available through
the message-reply-headers variable, which is a
vector of the following headers: number subject from date id
references chars lines xref extra.
In the case of a string value, if the match is a
regular expression, or if it takes the form (header
match regexp), a
‘gnus-match-substitute-replacement’ is
proceed on the value to replace the positional parameters
‘\n’ by the corresponding
parenthetical matches (see See
Replacing the Text that Matched in The Emacs Lisp
Reference Manual.)
If you wish to check whether the message you are about to
compose is meant to be a news article or a mail message, you can
check the values of the message-news-p and
message-mail-p functions.
So here’s a new example:
(setq gnus-posting-styles
'((".*"
(signature-file "~/.signature")
(name "User Name")
(x-face-file "~/.xface")
(x-url (getenv "WWW_HOME"))
(organization "People's Front Against MWM"))
("^rec.humor"
(signature my-funny-signature-randomizer))
((equal (system-name) "gnarly") ;; A form
(signature my-quote-randomizer))
(message-news-p ;; A function symbol
(signature my-news-signature))
(window-system ;; A value symbol
("X-Window-System" (format "%s" window-system)))
;; If I’m replying to Larsi, set the Organization header.
((header "from" "larsi.*org")
(Organization "Somewhere, Inc."))
;; Reply to a message from the same subaddress the message
;; was sent to.
((header "x-original-to" "me\\(\\+.+\\)@example.org")
(address "me\\1@example.org"))
((posting-from-work-p) ;; A user defined function
(signature-file "~/.work-signature")
(address "user@bar.foo")
(body "You are fired.\n\nSincerely, your boss.")
("X-Message-SMTP-Method" "smtp smtp.example.org 587")
(organization "Important Work, Inc"))
("nnml:.*"
(From (with-current-buffer gnus-article-buffer
(message-fetch-field "to"))))
("^nn.+:"
(signature-file "~/.mail-signature"))))
The ‘nnml:.*’ rule means that you use
the To address as the From address in
all your outgoing replies, which might be handy if you fill many
roles. You may also use message-alternative-emails
instead. See
Message Headers in Message Manual.
Of particular interest in the “work-mail” style is the ‘X-Message-SMTP-Method’ header. It specifies how to send the outgoing email. You may want to sent certain emails through certain SMTP servers due to company policies, for instance. See Message Variables in Message Manual.
Next: Drafts, Previous: Archived Messages, Up: Composing Messages [Contents][Index]